
<template>
    <ul class="tabs">
        <li v-for="item in dataSource" :key="item.value"
        @click="select(item)"
        :class="liClass(item)">
            {{ item.text }}
        </li>
    </ul>
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';

type dataSourceItem = { text: string, value: string }

@Component
export default class Tabs extends Vue {
    @Prop({ required: true, type: Array }) dataSource!: dataSourceItem[]
    @Prop() readonly value!: string;
    @Prop(String) classPre?: string;
    liClass(item:dataSourceItem){
        return {
            selected: item.value === this.value,
            [this.classPre + "-type-item"]: this.classPre,
        }
    }
    select(item:dataSourceItem){
        this.$emit('update:value', item.value)
    }
}
</script>

<style lang="scss" scoped>
.tabs {
    background: #c4c4c4;
    display: flex;
    text-align: center;
    font-size: 24px;
    user-select: none;
    >li {
        width: 50%;
        height: 64px;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;

        &.selected::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: #333;
        }
    }
}
</style>